package com.lin.chapter32.chapter3.observer;

import com.lin.chapter32.chapter3.Recorder;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Client {
	public static void main(String[] args) throws IOException {
		DnsServer sh = new SHDnsServer();
		DnsServer china = new ChinaTopDnsServer();
		DnsServer top = new TopDnsServer();

		china.setUpperServer(top);
		sh.setUpperServer(china);

		System.out.println("====域名解析模拟器====");
		while (true){
			System.out.println("\n请输入域名（输入N退出）：");
			String domain = (new BufferedReader(new InputStreamReader(System.in))).readLine();
			if (domain.equalsIgnoreCase("n")){
				return;
			}
			Recorder recorder = new Recorder();
			recorder.setDomain(domain);
			sh.update(null, recorder);
			System.out.println("-----域名解析结果----");
			System.out.println(recorder);
		}
	}
}
